package edu.jptest.action;

import com.opensymphony.xwork2.ActionSupport;

import edu.jptest.bean.User;
import edu.jptest.serviceImp.UserService;

public class ActivationUserAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8046939219657802999L;
	private User user;
	private String email;
	private String validateCode;

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getValidateCode() {
		return validateCode;
	}

	public void setValidateCode(String validateCode) {
		this.validateCode = validateCode;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	// 发送邮件确认用户丢失密码 发送激活链接
	public String lostPassConfirm() {
		UserService userService = new UserService();
		if (!userService.UserNameOk(user.getUserName())) {
			int userId = userService.getUserIdByEmail(user.getUserEmail());
			String validateCode = userService.getUserByUserId(userId)
					.getUserPassword();
			try {
				userService.lostPassConfirm(user.getUserEmail(), validateCode);
			} catch (Exception e) {
				System.out.println("邮件通知密码更改出错");
			}
		}
		return SUCCESS;
	}

	// 点击激活邮件获得密码
	public String lostPassActivation() {
		UserService userService = new UserService();

		if (!userService.userValidate(email, validateCode)) {
			try {
				userService.lostPassActivation(email);
			} catch (Exception e) {
				System.out.println("用户激活密码错误！");
			}
		}
		return SUCCESS;
	}
}
